define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'inventory/inventorylog/index' + location.search,
                    add_url: 'inventory/inventorylog/add',
                    edit_url: 'inventory/inventorylog/edit',
                    del_url: 'inventory/inventorylog/del',
                    multi_url: 'inventory/inventorylog/multi',
                    import_url: 'inventory/inventorylog/import',
                    table: 'inventory_log',
                }
            });

            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                       // {field: 'shop_id', title: __('Shop_id')},
                        {field: 'goods.code', title: '商品编号'},
                        {field: 'goods.title', title: '商品标题'},
                        {field: 'goods.image', title: '商品主图',events: Table.api.events.image, formatter: Table.api.formatter.image},
                       // {field: 'goods.unit', title: '单位'},
                       // {field: 'sku.difference', title: '规格'},
                        {field: 'sku.code', title: 'SKU编号'},

                        // {field: 'sku_id', title: __('Sku_id')},
                        // {field: 'goods_id', title: __('Goods_id')},
                        {field: 'type', title: __('Type'), operate: 'LIKE', searchList: {"0":__('出库'),"1":__('入库')},formatter: Table.api.formatter.normal},
                        {field: 'change', title: __('Change'), operate: 'LIKE'},
                        {field: 'quantity', title: __('Quantity')},
                        {field: 'remarks', title: __('Remarks'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'inventory', title: __('Inventory'), operate: false},
                        {field: 'order_id', title: __('订单编号')},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'staff.name', title: __('操作人')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
